var EnemyManager = function() {
	// Array of enemies
	this.entities = [];

	// Level
	this.map = null;

	// Last Pop
	this.lastPop = +new Date();

	this.createEntity = function() {
		var c_index = this.entities.length;
		this.entities.push(new Enemy());

		var spawn = {x: -this.map.bounds.w, y: this.map.bounds.groundLevel};

		if(rand(0, 5) > 3) {
			spawn.x = this.map.bounds.w/2;
		}

		this.entities[c_index].init(spawn.x, spawn.y);
	}

	this.update = function(dt) {
		if (interval(this.lastPop, 3)) {
			this.createEntity();
			this.lastPop = +new Date();
		}

		if (map != undefined) 
			this.map = map;
		for (e in this.entities) {
			this.entities[e].update(dt);
		}
	}

	this.render = function(ctx) {
		for (e in this.entities) {
			this.entities[e].render(ctx);
		}
	}

	this.kill = function(index) {
		this.entities.splice(index, 1);
	}
};
EnemyManager = new EnemyManager();